package com.ying.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.*;

@Configuration
@EnableWebMvc
public class WebConfigurer extends WebMvcConfigurerAdapter {

    /**
     * 静态资源配置
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/META-INF/resources/")
                .addResourceLocations("classpath:/public/");
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    }

    /**
     * 视图控制器
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("/admin/login");
        registry.addViewController("/admin").setViewName("/admin/login");
        registry.addViewController("/admin/login.html").setViewName("/admin/login");
        registry.addViewController("/error/404.html").setViewName("/error/404");
        registry.addViewController("/error/500.html").setViewName("/error/500");
        registry.addViewController("/comm/myinc.html").setViewName("/comm/myinc");
        registry.addViewController("/comm/mytags.html").setViewName("/comm/mytags");
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
    }
}
